package com.bw.wxy.mvp.base.prsenter;

import android.util.Log;

import com.bw.wxy.mvp.model.entity.BaseEntity;
import com.bw.wxy.mvp.base.model.IModel;
import com.bw.wxy.mvp.base.view.IView;

import io.reactivex.Observer;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

public abstract class BasePresenter<M extends IModel,V extends IView> implements IPresenter, Observer<BaseEntity> {

    protected M mModel;
    protected V mView;
    protected CompositeDisposable compositeDisposable;
    public BasePresenter(M mModel, V mView) {
        this.mModel = mModel;
        this.mView = mView;
        compositeDisposable=new CompositeDisposable();
    }



    @Override
    public void onDestroy() {
        compositeDisposable.dispose();
        compositeDisposable.clear();
    }

    @Override
    public void onSubscribe(@NonNull Disposable d) {
        Log.i("wxy", "onSubscribe: "+11);
        compositeDisposable.add(d);
        mView.showDialog();
    }

    @Override
    public void onError(@NonNull Throwable e) {
        mView.showMessage(e.getMessage());
    }

    @Override
    public void onComplete() {
        mView.hideDialog();
    }
}

